<template>
  <div>
    <el-dialog v-dialogDrag title="编辑" :visible="isShowEditDialog" width="40%" @close="dialogClose">
      <el-form ref="editForm" :model="ruleForm" :rules="rules" label-width="auto">
        <el-form-item :label="cyyType" prop="type">
          <el-select v-model="ruleForm.type">
            <el-option v-for="item in CyyTypeOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="cyyContent" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitData()" class="pull-right margin-l-25">确定
          </el-button>
          <el-button @click="dialogClose" class="pull-right">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { updateCyy } from "@/api/evaluation/word";
import { findByName } from "@/api/systemManage/dataDictionary";
export default {
  //接受父组件
  props: {
    isShowEditDialog: {
      type: Boolean,
    },
    record: {
      type: Object
    }
  },

  data () {
    return {
      cyyContent: '',
      cyyType: '',
      CyyTypeOptions: [],
      ruleForm: {
        name: "",
        type: "",
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入内容",
            trigger: "change,blur",
          },
        ],
        type: [
          {
            required: true,
            message: "请选择类型",
            trigger: "change,blur",
          },
        ],
      },
    };
  },
  methods: {
    dialogClose () {
      this.$emit("dialogClose");
    },
    submitData () {
      this.$refs.editForm.validate((valid) => {
        if (!valid) {
          return;
        } else {
          updateCyy(this.ruleForm).then((res) => {
            this.$emit("close");
            this.$emit("dialogClose");
          })
        }
      })
    },
    getOption () {
      findByName("input=" + "业务类型").then((res) => {
        for (var i = 0; i < res.data.length; i++) {
          if (res.data[i].dictName == '业务类型' && this.record.type == res.data[i].dictValue) {
            findByName("input=" + "业务类型").then((res) => {
              for (let j = 0; j < res.data.length; j++) {
                if (res.data[j].dictName == '业务类型')
                  this.CyyTypeOptions.push({
                    label: res.data[j].dictValue,
                    value: res.data[j].dictValue,
                  });
              }
              this.cyyContent = '评估目的'
              this.cyyType = '业务类型'
              return
            });
          }
        }
      });
      findByName("input=" + "常用语类型").then((res) => {
        for (let i = 0; i < res.data.length; i++) {
          if (res.data[i].dictName == '常用语类型' && this.record.type == res.data[i].dictValue) {
            findByName("input=" + "常用语类型").then((res) => {
              for (let j = 0; j < res.data.length; j++) {
                if (res.data[j].dictName == '常用语类型')
                  this.CyyTypeOptions.push({
                    label: res.data[j].dictValue,
                    value: res.data[j].dictValue,
                  });
              }
              this.cyyContent = '常用语'
              this.cyyType = '常用语类型'
            });
          }
        }
      })
    },
  },
  mounted () {
    this.ruleForm = Object.assign({}, this.record)
    this.getOption()
  }
};
</script>

<style lang="less" scoped>

</style>
